/**
 * @author zhangchenguang
 * @created 2020/03/12
 * @describe aes加密  传入原始数据  return 加密/解密值
 */
import CryptoJS from '@/common/aes.js'
// 加密
CryptoJS.$aesJiaM = (encrypted) => {
  if (localStorage.getItem('NEWAES') && encrypted) {
    var NEWAESlist = localStorage.getItem('NEWAES').split(',')
    // var NEWAESlist = '185674f6-8f2e-4a9a-8a0c-9e13dc368cda,68b74b88-f890-422e-a3e0-dcbe5d4e45ee'
    var key = CryptoJS.enc.Hex.parse(NEWAESlist[0])
    var iv = CryptoJS.enc.Hex.parse(NEWAESlist[1])
    var string = encrypted
    var data = CryptoJS.AES.encrypt(string, key, {
      iv: iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7
    })
    var uncrypted = data.toString()
    return uncrypted
  }
}
//   解密
CryptoJS.$aesJieM = (encrypted) => {
  if (localStorage.getItem('NEWAES') && encrypted) {
    var NEWAESlist = localStorage.getItem('NEWAES').split(',')
    var key = CryptoJS.enc.Hex.parse(NEWAESlist[0])
    var iv = CryptoJS.enc.Hex.parse(NEWAESlist[1])
    var string = encrypted
    var data = CryptoJS.AES.decrypt(string, key, {
      iv: iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7
    })
    var uncrypted = data.toString(CryptoJS.enc.Utf8)
    return uncrypted
  }
}
export default CryptoJS
